package com.eff.android.fragment.main.start;

import com.eff.android.R;
import com.eff.android.api.model.Setting;
import com.eff.android.fragment.EBaseFragment;
import com.eff.android.fragment.IFragmentCallback;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class EMainFragmentStartRecord extends EBaseFragment{
	
	public static final String TAG = EMainFragmentStartRecord.class.getSimpleName();
	
	Button btnStartAgain;
    Fragment eMainFragmentPronounciation;
    
    private IFragmentCallback callback;

    int n;
	
	public static EMainFragmentStartRecord newInstance(Bundle b) {
		EMainFragmentStartRecord f = new EMainFragmentStartRecord();
		if (b != null){
		    f.setArguments(b);
		}
		return f;
	}

	public static Bundle getArgs() {
		Bundle b = new Bundle();
		b.putString(TAG, TAG);
		return b;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		initFragments();
	}

	private void initFragments() {
		eMainFragmentPronounciation = EMainFragmentPronounciation.newInstance(null);
	}
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
	    Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		
		View v = inflater.inflate(R.layout.e_frm_main_start, container, false);
		btnStartAgain = (Button)v.findViewById(R.id.btn_start_again);
		btnStartAgain.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				getCallback().gotoNextPage(eMainFragmentPronounciation);
			}
		});
		initViews(v);
		    
		return v;
    }

	private void initViews(View v) {
		Setting settings = Setting.newInstance();
		
		TextView subject = (TextView) v.findViewById(R.id.subjectTextView);
		subject.setText("Subject: " + settings.getSubject().toString());
		
		TextView level = (TextView) v.findViewById(R.id.levelTextView);
		level.setText("Level: " + settings.getLevel().toString());
		
		TextView numberOfFalseWordTextView = (TextView) v.findViewById(R.id.numberTextView);
		int numberOfFalseWord = this.getArguments().getInt("numberOfFalseWord");
		numberOfFalseWordTextView.setText("Number of false word: " + numberOfFalseWord);
		
	}

	public IFragmentCallback getCallback() {
		return callback;
	}

	public void setCallback(IFragmentCallback callback) {
		this.callback = callback;
	}

}